package org.john.guavatest;

import com.google.common.net.InetAddresses;

import java.net.Inet4Address;
import java.net.Inet6Address;
import java.net.InetAddress;

/**
 * Created by adsame on 18-12-20.
 */
public class IPTest {
    public static void main(String args[]) {
        String ip[] = {"10.23.43.4", "::127.0.0.1", "1080::1", "::1", "::ffff:49", "::ffff:110.253.64.126"};
        for (int i = 0; i < ip.length; ++i) {
            System.out.println("current:" + ip[i]);
            System.out.println(InetAddresses.isMappedIPv4Address(ip[i]));
            InetAddress inetAddr = InetAddresses.forString(ip[i]);
            System.out.println("is ipv4:" + (inetAddr instanceof Inet4Address));
            System.out.println("is ipv6:" + (inetAddr instanceof Inet6Address));
            Inet4Address inet4Addr = InetAddresses.getCoercedIPv4Address(inetAddr);
            System.out.println("InetAddresses.coerceToInteger:" + InetAddresses.coerceToInteger(inet4Addr));
            System.out.println("InetAddresses.toAddrString:" + InetAddresses.toAddrString(inetAddr));
            System.out.println("InetAddresses.toUriString:" + InetAddresses.toUriString(inet4Addr));
            System.out.println("inetAddr.toString:" + inetAddr.toString());
            System.out.println("inetAddr.getHostAddress:" + inetAddr.getHostAddress());
            System.out.println("inet4Addr.getHostAddress:" + inet4Addr.getHostAddress());
        }

    }
}
